package com.hainabo.mgcmall.api.wx;

import com.hainabo.bootside.core.common.ReturnVO;
import com.hainabo.mgcmall.dao.DriversLicenseRespository;
import com.hainabo.mgcmall.model.DriversLicenseInfo;
import com.hainabo.mgcmall.util.JsonUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.loader.custom.Return;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.Map;

/**
 * Created by guoshihao on 2017/12/10.
 */
@Api(value = "/wx/driversInfo")
@Component
@Path("/wx/driversInfo")
@Produces(MediaType.APPLICATION_JSON)
@Slf4j
public class WxDriversLicenseResource {

    @Autowired
    private DriversLicenseRespository driversLicenseRespository;

    @POST
    @Path("save")
    public ReturnVO save(String json){
        DriversLicenseInfo driversLicenseInfo = JsonUtil.toBean(json,DriversLicenseInfo.class);
        return new ReturnVO(driversLicenseRespository.save(driversLicenseInfo));
    }



    @POST
    @Path("getInfo")
    public ReturnVO getInfo(String json){
        Map param = JsonUtil.toHashMap(json);
        DriversLicenseInfo d = driversLicenseRespository.findByUserId(Long.valueOf(param.get("userId").toString()));
        return new ReturnVO(d);
    }

}
